<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Encyclopedias extends Model
{
    public $timestamps = false;
    protected $connection = 'xz';
    protected $table = 'encyclopedias';
    use HasFactory;

    public function getCreateTimeAttribute(string $value)
    {
        return Date("Y-m-d H:i:s",$value);
    }

    public function types()
    {
        return $this->hasOne('App\Models\EncyclopediasType','id','type')->select('id','name');
    }

    public function likes()
    {
        return $this->hasMany('App\Models\EncyclopediasLike','interaction_id','id')->select('id','uid','interaction_id');
    }

    public function collections()
    {
        return $this->hasMany('App\Models\EncyclopediasCollect','interaction_id','id')->select('id','uid','interaction_id');
    }

    public function comments()
    {
        return $this->hasMany('App\Models\EncyclopediasReply','article_id','id')->with('user')->with('likes')->select('id','user_id','content','review','create_time');
    }
}
